﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace SMS.Magus
{
    public partial class frmMovebyCombin : DevExpress.XtraEditors.XtraForm
    {
        public XtraUserControl ParentControl { get; set; }
        private string opflag = "";
        public frmMovebyCombin(string op)
        {
            InitializeComponent();
            this.opflag = op;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            txtNo8.Enabled = true;
            combLen.Enabled = false;
            combCount.Enabled = false;
            txtNum.Enabled = false;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            txtNo8.Enabled = false;
            combLen.Enabled = true;
            combCount.Enabled = false;
            txtNum.Enabled = false;
            combLen.Text = "2";
            
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            txtNo8.Enabled = false;
            combLen.Enabled = false;
            combCount.Enabled = true;
            txtNum.Enabled = true;
            combCount.Text = "2";
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnMove_Click(object sender, EventArgs e)
        {
            frmAutoTel autel = (frmAutoTel)this.ParentControl;
            if (!autel.isnullorint(txtNo8.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("必须是数字！");
                txtNo8.Focus();
                return;
            }
            //包含指定的数字
            if (radioButton1.Checked)
            {
                string str = txtNo8.Text;
                //是否需要禁止str为空
                if (opflag.Equals("up"))
                {
                    if (autel.lvObjectNo.Items.Count > 0)
                    {
                        foreach (ListViewItem it in autel.lvObjectNo.Items)
                        {
                            if (it.Text.IndexOf(str) >= 0)
                            {   //从下移动到上方
                                autel.lvSourceNo.Items.Add(it.Text);
                                autel.lvObjectNo.Items.Remove(it);
                            }
                        }
                    }
                }
                else
                {
                    if (autel.lvSourceNo.Items.Count > 0)
                    {
                        foreach (ListViewItem it in autel.lvSourceNo.Items)
                        {
                            if (it.Text.IndexOf(str) >= 0)
                            {   
                                autel.lvObjectNo.Items.Add(it.Text);
                                autel.lvSourceNo.Items.Remove(it);
                            }
                        }
                    }
                }

            }
            //存在n个x的情况，x不固定
            if (radioButton2.Checked)
            {
                if (combLen.Text == "")
                {
                    combLen.Text = "2";
                }
                if (!autel.isnullorint(combLen.Text))
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("必须是2-5的数字！");
                    combLen.Text = "2";
                    combLen.Focus();
                    return;
                }
                int len = Int16.Parse(combLen.Text);
                for (int k = 0; k < 10; k++)
                {
                    string str = k.ToString();
                    for (int i = 1; i < len; i++)
                    {
                        str += k.ToString();
                    }
                    if (opflag.Equals("up"))
                    {
                        if (autel.lvObjectNo.Items.Count > 0)
                        {
                            foreach (ListViewItem it in autel.lvObjectNo.Items)
                            {
                                if (it.Text.IndexOf(str) >= 0)
                                {   //从下移动到上方
                                    autel.lvSourceNo.Items.Add(it.Text);
                                    autel.lvObjectNo.Items.Remove(it);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (autel.lvSourceNo.Items.Count > 0)
                        {
                            foreach (ListViewItem it in autel.lvSourceNo.Items)
                            {
                                if (it.Text.IndexOf(str) >= 0)
                                {
                                    autel.lvObjectNo.Items.Add(it.Text);
                                    autel.lvSourceNo.Items.Remove(it);
                                }
                            }
                        }
                    }
                }

            }
            //存在n个x的情况，x固定
            if (radioButton3.Checked)
            {
                if (combCount.Text == "")
                {
                    combCount.Text = "2";
                }
                if (!autel.isnullorint(combCount.Text))
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("必须是2-6的数字！");
                    combCount.Text = "2";
                    combCount.Focus();
                    return;
                }
                int len = Int16.Parse(combCount.Text);
                if (!autel.isnullorint(txtNum.Text))
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("必须是数字！");
                    txtNum.Focus();
                    return;
                }
                string str = txtNum.Text;
                //是否需要禁止str为空
                for(int i=1;i<len;i++)
                {
                    str += txtNum.Text;
                }
                //DevExpress.XtraEditors.XtraMessageBox.Show(str, "提示", MessageBoxButtons.OK);
                
                if (opflag.Equals("up"))
                {
                    if (autel.lvObjectNo.Items.Count > 0)
                    {
                        foreach (ListViewItem it in autel.lvObjectNo.Items)
                        {
                            if (it.Text.IndexOf(str) >= 0)
                            {   //从下移动到上方
                                autel.lvSourceNo.Items.Add(it.Text);
                                autel.lvObjectNo.Items.Remove(it);
                            }
                        }
                    }
                }
                else
                {
                    if (autel.lvSourceNo.Items.Count > 0)
                    {
                        foreach (ListViewItem it in autel.lvSourceNo.Items)
                        {
                            if (it.Text.IndexOf(str) >= 0)
                            {
                                autel.lvObjectNo.Items.Add(it.Text);
                                autel.lvSourceNo.Items.Remove(it);
                            }
                        }
                    }
                }
            }
            this.Close();
        }
        
    }
}
